package com.leyu.mall.admin.mdm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.leyu.mall.domain.mdm.MDMCity;
import com.leyu.mall.service.mdm.IMDMCityService;

@Controller
@Scope(value = "prototype")
@RequestMapping("admin/city")
public class MDMCityController {

	
	@Autowired
	private IMDMCityService	mdmCityService;

	
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String index(Model model) throws Exception
	{
		try
		{
			model.addAttribute("citylist", mdmCityService.getMDMCityList());
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "admin/city.html";
	}
	
	@RequestMapping(value = "new", method = RequestMethod.GET)
	public String newMDMCity(Model model) throws Exception
	{
		return "admin/newcity.html";
	}
	
	
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public String save(Model model, MDMCity mdmCity)
	{
		try
		{
			mdmCityService.addMDMCity(mdmCity);
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "redirect:../city";
	}

	@RequestMapping(value = "delete/{cityId}", method = RequestMethod.GET)
	public String delete(Model model, @PathVariable long cityId)
	{
		try
		{
			mdmCityService.deleteMDMCity(cityId);
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "redirect:../../city";
	}

	@RequestMapping(value = "edit/{cityId}", method = RequestMethod.GET)
	public String edit(Model model, @PathVariable long cityId)
	{
		try
		{
			model.addAttribute("entity", mdmCityService.getMDMCityeById(cityId));
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "admin/editcity.html";
	}
}
